<%--
  Created by IntelliJ IDEA.
  User: 11076
  Date: 2018/12/3
  Time: 14:38
  To change this template use File | Settings | File Templates.
--%>

<%@ page language="java" contentType="text/html; charset=UTF-8"
                                        pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>

<!DOCTYPE html>
<html lang="en">
<head>
    <%@ include file="../../base/top.jsp" %>

    <style>
        /*#checkedLabel span{*/
            /*margin-left: 5px;*/
            /*margin-right: 5px;*/
        /*}*/

    </style>
</head>
<body>
<div class="main-container" id="main-container">
    <!-- /section:basics/sidebar -->
    <div class="main-content">
        <div class="main-content-inner">
            <div class="page-content">
                <div class="row">
                    <div class="col-xs-12">

                        <table id="table_report" class="table table-striped table-bordered table-hover">
                            <input type="text" name="labelLibId" id="labellib-id" style="display: none"/>
                            <input type="text" name="success" id="success" style="display: none"/>
                            <input type="text" name="msg" id="msg" style="display: none"/>
                            <tr>
                                <td style="text-align: right;width: 100px">项目名称:</td>
                                <td><input type="text" id="group-name" value="" maxlength="30" placeholder="这里输入名称" title="名称" style="width:98%;"/></td>
                            </tr>
                            <tr>
                                <td style="text-align: right;">请选择组长:</td>
                                <td>
                                    <div>
                                        <ul class="list-inline">
                                            <c:forEach items="${stuInfos}" var="studentInfo">
                                                <li><label><input name="headman" type="radio" value="${studentInfo.stuId}" />${studentInfo.stuName} </label></li>
                                            </c:forEach>
                                        </ul>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td style="text-align: right;">请选择组员:</td>
                                <td id="checkedLabel">
                                    <%--<span class="label label-default">格式错误</span>--%>
                                    <div id="check-member">
                                        <ul class="list-inline" id="headman">
                                            <c:forEach items="${stuInfos}" var="studentInfo">
                                                <li><label class="checkbox"><input class="ace" id="${studentInfo.stuId}" type="checkbox" value="cheese"><span class="lbl"></span> ${studentInfo.stuName}</label></li>
                                            </c:forEach>
                                        </ul>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td style="text-align: right;">备注:</td>
                                <td  style="padding-top: 13px;">
                                </td>
                            </tr>
                            <tr>
                                <td style="text-align: center;" colspan="10">
                                    <button id="save-btn" class="btn btn-mini btn-primary" onclick="save()">保存</button>
                                    <button class="btn btn-mini btn-danger" onclick="top.Dialog.close()">取消</button>
                                </td>
                            </tr>
                        </table>
                    </div>
                    <!-- /.col -->
                </div>
                <!-- /.row -->
            </div>
            <!-- /.page-content -->
        </div>
    </div>
    <!-- /.main-content -->
</div>
<!-- basic scripts -->

<!-- 页面底部js¨ -->
<%@ include file="../../base/foot.jsp" %>


<script>
    //保存标签库信息
    function save() {
        var groupName =$("#group-name").val();
        var headmanId =$('input[name="headman"]:checked').val();
        var members = new Array();

        for (var i = 0; i < $("#check-member input:checkbox:checked").length; i++) {
            var member = $("#check-member input:checkbox:checked").eq(i).attr("id");
            members.push(member);
        }
        $.ajax({
            url:"group/addGroup",
            type:"POST",
            dataType: "json",
            data:{
                groupName:groupName,
                headmanId:headmanId,
                members:members.join()
            },
            success:function (data) {
                $("#success").val(data["success"]);
                $("#msg").val(data["msg"]);
                //关闭一定要写在ajax执行完成之后
                top.Dialog.close();
            }
        })
    }

    function setCheckAndUsingLabel() {

        $("input[type='checkbox']").each(function () {
            $(this).attr("id");
        });

    }

    /**
     * 检查表单格式
     *
     * @create on 2018/11/27 by johnny
     * @update on 2018/12/27 by johnny
     */
    function checkFormats() {
        if($("#labellib-name").val()==null || $("#labellib-name").val()==""){
            top.operateError("标签库名不能为空");
            $("#labellib-name").focus();
            return false;
        }
        var reg =/^[\u4e00-\u9fa5]{1,8}$/g;
        if(reg.test($("#labellib-name").val())){
            return true;
        }else{
            top.operateError("标签库名必须为1-8个中文");
            $("#labellib-name").focus();
            return false;
        }
        return false;
    }

</script>
</body>
</html>
